package com.example.administrator.aidldemo;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

public class APPService extends Service {
    public APPService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
      //  throw new UnsupportedOperationException("Not yet implemented");
        return new IMyAidlInterface.Stub() {
            @Override
            public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {

            }

            @Override
            public void setData(String data) throws RemoteException {
                APPService.data = data;
                System.out.println("数据为："+data);
                Intent intent1 = new Intent();
                intent1.setAction("mhysa");
                intent1.putExtra("data",data);
                sendBroadcast(intent1);
            }
        };
    }

    @Override
    public void onCreate() {
        super.onCreate();
        System.out.println("start service");
        running = true;
        System.out.println("data="+data);
      /*  while(running){

            new Thread(

                    new Runnable() {
                        @Override
                        public void run() {

                            System.out.println("data="+data);
                            try {
                                Thread.sleep(1000);


                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    }
            ).start();*/
       // }
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        System.out.println("data="+data);
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        running = false;
        System.out.println("stop service");
    }

    private static String data = "默认数据";
    private boolean running = false;
    
}
